package com.example.administrator.yuejian2.activity;

import android.graphics.ColorSpace;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.adapter.MultipleItemQuickAdapter;
import com.example.administrator.yuejian2.bean.ActivityBean;
import com.example.administrator.yuejian2.bean.ClubBean;
import com.example.administrator.yuejian2.bean.MultipleItem;
import com.example.administrator.yuejian2.bean.SharePictureBean;
import com.example.administrator.yuejian2.model.ActivityModel;
import com.example.administrator.yuejian2.model.ClubModel;
import com.example.administrator.yuejian2.model.SharePicModel;

import java.util.ArrayList;
import java.util.List;

public class duobujuActivity extends AppCompatActivity {


    private RecyclerView recyclerView;
    private List<ClubBean> datas01;
    private List<ActivityBean> dataactivity;
    private List<SharePictureBean> datashare;
    private List<MultipleItem> datas02;
    private MultipleItemQuickAdapter adapter;
    private RetrofitListener<List<ActivityBean>> aclistener;
    private RetrofitListener<List<SharePictureBean>> splistener;
    private RetrofitListener<List<ClubBean>> listener;
    private int length,length1,length2,length3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_duobuju);
        recyclerView = findViewById(R.id.duobujurecyler);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new MultipleItemQuickAdapter(datas02);
        recyclerView.setAdapter(adapter);
        datas02 = new ArrayList<>();
        dataactivity=new ArrayList<>();
        datashare=new ArrayList<>();
        listener=new RetrofitListener<List<ClubBean>>() {
            @Override
            public void onSuccess(List<ClubBean> clubBeans, int flag) {
                            datas01=clubBeans;
                            length1=datas01.size();
                for (int i = 0; i < length1; i++) {
                    if (i%3==0)
                      {
                        datas02.add(new MultipleItem(MultipleItem.NORMAL_TYPE, datas01.get(i)));
                        adapter.addData(datas02);
                    }
                    else {
                        datas02.add(new MultipleItem(MultipleItem.FIRST_TYPE));
                     //   adapter.addData(datas02);
                    }
                }
            }

            @Override
            public void onFail() {

            }
        };


        adapter.setSpanSizeLookup(new BaseQuickAdapter.SpanSizeLookup() {
            @Override
            public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
                return Integer.parseInt(datas01.get(position).getClub_id());
            }
        });

        splistener=new RetrofitListener<List<SharePictureBean>>() {
            @Override
            public void onSuccess(List<SharePictureBean> sharePictureBeans, int flag) {
                datashare=sharePictureBeans;
                length2=datashare.size();

                for (int i = 0; i < length2; i++) {
                    if (i%5==0)
                    {
                        datas02.add(new MultipleItem(MultipleItem.SECOND_TYPE, datashare.get(i)));
                        adapter.addData(datas02);
                    }
                }
            }

            @Override
            public void onFail() {

            }
        };

        aclistener=new RetrofitListener<List<ActivityBean>>() {
            @Override
            public void onSuccess(List<ActivityBean> list, int flag) {
                dataactivity=list;
                length3=dataactivity.size();

                for (int i = 0; i < length3; i++) {
                    if (i%7==0)
                    {
                        datas02.add(new MultipleItem(MultipleItem.NORMAL_TYPE, dataactivity.get(i)));
                        adapter.addData(datas02);
                    }
                }

            }

            @Override
            public void onFail() {

            }
        };

            club();
      //  SharepicList();
        //getactivity();
    }

    private void club() {
        ClubModel activityModel = new ClubModel();
        activityModel.clubList(listener);
    }
    private void SharepicList(){
        SharePicModel picModel = new SharePicModel();
        picModel.sharepicList(splistener);
    }

    private void getactivity()
    {
        ActivityModel activityModel=new ActivityModel();
        activityModel.activityList(aclistener);
    }

}
